﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library.CommonClass;

namespace Lamex.mIE.Calculate
{
   public class LGC_TIM_T02_BENDING
    {
        public static double LGC_TIM_T02_BENDING_VALUE(string DWG_NO,string PART_NO,  string Feat_Value)
        {
            string errorMessage = DWG_NO + ";" + PART_NO + ";" + Feat_Value;
            try
            {
                
                int ToolNum = 0;
                switch (Feat_Value)
                {
                    case "Z字":
                        ToolNum = 3;
                        break;
                    case "几字":
                        ToolNum = 4;
                        break;
                    case "铁层板":
                        ToolNum = 8;
                        break;
                    case "其它":
                        ToolNum = 10;
                        break;
                    default:
                        break;
                }
                   


                    double LGC_TIM_T02_BENDING = 0;
                double W = 0;
                double D = 0;
                DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * from IE_Part_SizeParmList where DWG_NO='" + DWG_NO + "' and PART_NO='" + PART_NO + "'");
                if (dt.Rows.Count == 0)
                {
                    //XtraMessageBox.Show("【尺寸参数表没有该部件号,此数据不能作为保存数据,请确保尺寸参数表存有该数据】");
                    Lamex.Common.IniFile ini = new Lamex.Common.IniFile(Application.StartupPath + "\\RecordLostWorkTime.ini");
                    string str = ini.IniReadValue("Configuration", "RecoredName");
                    str += @"\r\n" + errorMessage+ "尺寸参数表没有该部件号";
                    ini.IniWriteValue("Configuration", "RecoredName", str);
                    return 0;
                }
                if (dt.Rows[0]["WIDTH"].ToString() != "")
                    W = double.Parse(dt.Rows[0]["WIDTH"].ToString());
                else
                    W = 0;
                if (dt.Rows[0]["DEPTH"].ToString() != "")
                    D = double.Parse(dt.Rows[0]["DEPTH"].ToString());
                else
                    D = 0;
                if (W > 1800 && D > 700)
                    LGC_TIM_T02_BENDING = (6 * 12.17 + 20 * 4) * 2;
                else
                    LGC_TIM_T02_BENDING = 16 * ToolNum;
                return  LGC_TIM_T02_BENDING;
            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message+":"+ errorMessage);
                return 0;
            }
        }
    }
}
